# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=de4dot
pkgver=2090.b7d5728
pkgrel=1
pkgdesc='.NET deobfuscator and unpacker.'
arch=('any')
groups=('blackarch' 'blackarch-windows' 'blackarch-unpacker' 'blackarch-binary'
        'blackarch-reversing')
url='https://github.com/de4dot/de4dot'
license=('GPL3')
depends=('mono')
makedepends=('git' 'mono' 'mono-msbuild')
source=("git+https://github.com/de4dot/$pkgname.git"
        "$pkgname.sh"
        "$pkgname-x64.sh")
sha512sums=('SKIP'
            '61c7a09497491ca4198df0320de43dabe1e67e414303b8dbe91e6b83c179eaf395d0dcbc8f9c6c078dc557b98cc21fc538c60b3f7430e42a34806aec64f6f95a'
            '600bd38aa72d10950486655be33c77a23f5364879369869f364163c5cbe53115bbe89e2c88c473d56a637a7f52232b11c07b85da14bba6f32f2c3b5b541c0958')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

build() {
  cd $pkgname

  msbuild -v:m -restore -t:Build -p:Configuration=Release \
    -p:TargetFramework=net45 de4dot.netframework.sln
  find Release/net45 -iname '*.pdb' -or -iname '*.xml' -or \
    -iname 'Test.Rename.*' -delete
}

package() {
  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"
  install -dm 755 "$pkgdir/usr/share/windows/$pkgname"

  cp -a $pkgname/Release/net45/* "$pkgdir/usr/share/$pkgname"
  install -Dm 755 "$pkgname.sh" "$pkgdir/usr/share/$pkgname/$pkgname.sh"
  install -Dm 755 "$pkgname-x64.sh" "$pkgdir/usr/share/$pkgname/$pkgname-x64.sh"

  ln -s "/usr/share/$pkgname/$pkgname.sh" "$pkgdir/usr/bin/$pkgname"
  ln -s "/usr/share/$pkgname/$pkgname-x64.sh" "$pkgdir/usr/bin/$pkgname-x64"

  cp -a "$pkgdir/usr/share/$pkgname"/* "$pkgdir/usr/share/windows/$pkgname/"

  rm "$pkgdir/usr/share/windows/$pkgname/"{de4dot.sh,de4dot-x64.sh}
}

